#include"compile_run.hpp"
#include"../Common/httplib.h"
using namespace ns_compile_run;
using namespace httplib;

int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cout << "User:" << "\n\t";
        std::cout << "Procedure" << " port" << std::endl;
    }
    Server svr;
    svr.Get("/hello",[](const Request &req,Response &res){
        res.set_content("这里是编译运行服务","text/plain;charset=utf-8");
    });

    svr.Post("/compile_and_run",[](const Request& req,Response &res){
        std::string in_json = req.body;
        std::string out_json;
        if(!in_json.empty())
        {
            CompileAndRun::Start(in_json,&out_json);
        }
        res.set_content(out_json,"application/json;charset=utf-8");
    });
    svr.listen("0.0.0.0",atoi(argv[1]));
    return 0;
}